﻿test("Test PackageHoliday class constructor", function () {
    var holiday = new OffersNS.PackageHoliday({
        id: "PH001",
        title: "Test Holiday",
        startDate: "01.07.2013",
        endDate: "08.07.2013",
        price: 395,
        thumbnailUrl: "images/cruise-greece.jpg",
        imageUrl: "images/cruise-greece.jpg",
        description: "This is one hell of a test holiday!",
        active: false,
        transportType: OffersNS.TransportType.air,
    })

    ok(holiday instanceof OffersNS.PackageHoliday, "Object is instance of PackageHoliday");
    deepEqual(holiday.id, "PH001", "Holiday id set correctly");
    deepEqual(holiday.title, "Test Holiday", "Holiday title set correctly");
    deepEqual(holiday.startDate, "01.07.2013", "Holiday startDate set correctly");
    deepEqual(holiday.endDate, "08.07.2013", "Holiday endDate set correctly");
    deepEqual(holiday.price, 395, "Holiday price set correctly");
    deepEqual(holiday.thumbnailUrl, "images/cruise-greece.jpg", "Holiday thumbnailUrl set correctly");
    deepEqual(holiday.imageUrl, "images/cruise-greece.jpg", "Holiday image set correctly");
    deepEqual(holiday.description, "This is one hell of a test holiday!", "Holiday description set correctly");
    ok(!(holiday.active), "Holiday active status is set to false");
    deepEqual(holiday.transportType, OffersNS.TransportType.air, "Holiday transport type set correctly")
});

test("Test Excursion class constructor", function () {
    var testExcursionItinerary = new OffersNS.Itinerary();

    testExcursionItinerary.add({
        city: "Istanbul",
        description: "Visit 1, 2, 3",
    });

    testExcursionItinerary.add({
        city: "Ankara",
        description: "Visit this and that",
    });

    var excursion = new OffersNS.Excursion({
        id: "E001",
        title: "Test Excursion",
        startDate: "01.07.2013",
        endDate: "08.07.2013",
        price: 395,
        thumbnailUrl: "images/cruise-greece.jpg",
        imageUrl: "images/cruise-greece.jpg",
        description: "This is one hell of a test excursion!",
        active: false,
        transportType: OffersNS.TransportType.combined,
        itinerary: testExcursionItinerary,
    })

    ok(excursion instanceof OffersNS.Excursion, "Object is instance of Excursion");
    deepEqual(excursion.id, "E001", "Excursion id set correctly");
    deepEqual(excursion.title, "Test Excursion", "Excursion title set correctly");
    deepEqual(excursion.startDate, "01.07.2013", "Excursion startDate set correctly");
    deepEqual(excursion.endDate, "08.07.2013", "Excursion endDate set correctly");
    deepEqual(excursion.price, 395, "Excursion price set correctly");
    deepEqual(excursion.thumbnailUrl, "images/cruise-greece.jpg", "Excursion thumbnailUrl set correctly");
    deepEqual(excursion.imageUrl, "images/cruise-greece.jpg", "Excursion image set correctly");
    deepEqual(excursion.description, "This is one hell of a test excursion!", "Excursion description set correctly");
    ok(!(excursion.active), "Excursion active status is set to false");
    deepEqual(excursion.transportType, OffersNS.TransportType.combined, "Excursion transport type set correctly");
    deepEqual(excursion.itinerary, testExcursionItinerary, "Excursion itinerary is the OffersNS.Itinerary instance passed to the constructor")
});

test("Test Cruise class constructor", function () {
    var cruise = new OffersNS.Cruise({
        id: "C001",
        title: "Test Cruise",
        startDate: "01.07.2013",
        endDate: "08.07.2013",
        price: 395,
        thumbnailUrl: "images/cruise-greece.jpg",
        imageUrl: "images/cruise-greece.jpg",
        description: "This is one hell of a test cruise!",
        active: false,
        waterbody: "Black Sea",
    })

    ok(cruise instanceof OffersNS.Cruise, "Object is instance of Cruise");
    deepEqual(cruise.id, "C001", "Cruise id set correctly");
    deepEqual(cruise.title, "Test Cruise", "Cruise title set correctly");
    deepEqual(cruise.startDate, "01.07.2013", "Cruise startDate set correctly");
    deepEqual(cruise.endDate, "08.07.2013", "Cruise endDate set correctly");
    deepEqual(cruise.price, 395, "Cruise price set correctly");
    deepEqual(cruise.thumbnailUrl, "images/cruise-greece.jpg", "Cruise thumbnailUrl set correctly");
    deepEqual(cruise.imageUrl, "images/cruise-greece.jpg", "Cruise image set correctly");
    deepEqual(cruise.description, "This is one hell of a test cruise!", "Cruise description set correctly");
    ok(!(cruise.active), "Cruise active status is set to false");
    deepEqual(cruise.waterbody, "Black Sea", "Cruise waterBody type set correctly")
});

test("Test TransportType enumeration", function () {
    deepEqual(OffersNS.TransportType.air, "Air", "TransportType.air value is 'Air'");
    deepEqual(OffersNS.TransportType.land, "Land", "TransportType.air value is 'Land'");
    deepEqual(OffersNS.TransportType.combined, "Combined", "TransportType.air value is 'Combined'");
    deepEqual(OffersNS.TransportType.own, "Own Transportation", "TransportType.air value is 'Own Transportation'");

    OffersNS.TransportType.air = "Train";
    deepEqual(OffersNS.TransportType.air, "Air", "After attempted change, TransportType.air value is still 'Air'");
});

test("Test Offer activate() and deactivate() methods", function () {
    var testOffer = new OffersNS.PackageHoliday({
        id: "PH001",
        title: "Test Holiday",
        startDate: "01.07.2013",
        endDate: "08.07.2013",
        price: 395,
        thumbnailUrl: "images/cruise-greece.jpg",
        imageUrl: "images/cruise-greece.jpg",
        description: "This is one hell of a test holiday!",
        active: false,
        transportType: OffersNS.TransportType.air,
    })

    testOffer.activate();
    ok(testOffer.active, "Offer status has changed to active");

    testOffer.deactivate();
    ok(!(testOffer.active), "Offer status has changed to NOT active");
});

test("Test Offer and PackageHoliday render() methods", function () {
    var testOffer = new OffersNS.PackageHoliday({
        id: "PH001",
        title: "Test Holiday",
        startDate: "01.07.2013",
        endDate: "08.07.2013",
        price: 395,
        thumbnailUrl: "images/cruise-greece.jpg",
        imageUrl: "images/cruise-greece.jpg",
        description: "This is one hell of a test holiday!",
        active: false,
        transportType: OffersNS.TransportType.air,
    })

    var fixture = jQuery("#qunit-fixture");
    var offer = testOffer.render();
    fixture.append(offer);

    var offerElements = fixture.children();
    ok(offerElements.length > 0, "Offer element has been generated");

    var id = document.getElementById("PH001");
    ok(id, "Main offer div exists");

    var thumbDiv = document.querySelector(".thumbnail");
    ok(thumbDiv, "Thumbnail div exists");

    var thumb = document.getElementsByTagName("img");
    ok(thumb[0].src, "Thumbnail image tag exists and has src");

    var title = document.querySelector(".offer-title");
    ok(title, "Title div exists");

    var transport = document.querySelector(".transport-type");
    ok(transport, "Transport div exists");

    var date = document.querySelector(".offer-date");
    ok(date, "Date div exists");

    var price = document.querySelector(".offer-price");
    ok(price, "Price div exists");

    var description = document.querySelector(".offer-description");
    equal(description.textContent, "This is one hell of a test holiday!", "Offer description matches");
});

test("Test Excursion spcific elements of render() method", function () {
    var testExcursionItinerary = new OffersNS.Itinerary();

    testExcursionItinerary.add({
        city: "Istanbul",
        description: "Visit 1, 2, 3",
    });

    testExcursionItinerary.add({
        city: "Ankara",
        description: "Visit this and that",
    });

    var testExcursion = new OffersNS.Excursion({
        id: "E001",
        title: "Test Excursion",
        startDate: "01.07.2013",
        endDate: "08.07.2013",
        price: 395,
        thumbnailUrl: "images/cruise-greece.jpg",
        imageUrl: "images/cruise-greece.jpg",
        description: "This is one hell of a test excursion!",
        active: false,
        transportType: OffersNS.TransportType.combined,
        itinerary: testExcursionItinerary,
    })

    var fixture = jQuery("#qunit-fixture");
    var excursion = testExcursion.render();
    fixture.append(excursion);

    var excursionElements = fixture.children();
    ok(excursionElements.length > 0, "Excursion element has been generated");

    var transport = document.querySelector(".transport-type");
    ok(transport, "Transport div exists");

    //var itinerary = document.querySelector(".offer-itinerary");
    //ok(itinerary, "Date div exists");
});

test("Test Cruise spcific elements of render() method", function () {
    var testCruise = new OffersNS.Cruise({
        id: "C001",
        title: "Test Cruise",
        startDate: "01.07.2013",
        endDate: "08.07.2013",
        price: 395,
        thumbnailUrl: "images/cruise-greece.jpg",
        imageUrl: "images/cruise-greece.jpg",
        description: "This is one hell of a test cruise!",
        active: false,
        waterbody: "Black Sea",
    })

    var fixture = jQuery("#qunit-fixture");
    var cruise = testCruise.render();
    fixture.append(cruise);

    var cruiseElements = fixture.children();
    ok(cruiseElements.length > 0, "Cruise element has been generated");

    var waterbody = document.querySelector(".offer-waterbody");
    ok(waterbody, "Waterbody div exists");
});